package cn.lili.controller.promotion;

import cn.lili.common.security.AuthUser;
import cn.lili.common.security.context.UserContext;
import cn.lili.common.security.enums.SceneEnums;
import cn.lili.common.utils.ResultUtil;
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.ReturnActivityGoods;
import cn.lili.modules.promotion.service.ReturnActivityGoodsService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

@RestController
@Api(tags = "全返卷商品")
@RequestMapping("/promotion/return/activityGoods")
@RequiredArgsConstructor
public class ReturnActivityGoodsController {

    @Resource
    private ReturnActivityGoodsService returnActivityGoodsService;

    @ApiOperation(value = "全返卷商品列表")
    @GetMapping
    public ResultMessage<Page<ReturnActivityGoods>> getPage(ReturnActivityGoods queryParam, PageVO page) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        if(SceneEnums.STORE.equals(currentUser.getScene())){
            queryParam.setStoreId(currentUser.getExtendId());
        }
        return ResultUtil.data(returnActivityGoodsService.getPage(queryParam, page));
    }

    @PostMapping
    @ApiOperation(value = "添加全返卷商品")
    public ResultMessage<Boolean> save(@RequestBody List<ReturnActivityGoods> saveParams) {
        AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser());
        return ResultUtil.data(returnActivityGoodsService.saves(saveParams,currentUser));
    }

    @ApiOperation(value = "删除全返卷商品")
    @DeleteMapping(value = "/{id}")
    public ResultMessage<Boolean> removeById(@PathVariable String id) {
        return ResultUtil.data(returnActivityGoodsService.removeById(id));
    }

    @PutMapping("/freeze/{id}")
    @ApiOperation(value = "冻结全返卷商品")
    public ResultMessage<Boolean> freeze(@PathVariable String id,@RequestBody ReturnActivityGoods returnActivityGoods) {
        return ResultUtil.data(returnActivityGoodsService.freeze(id,returnActivityGoods.getRemark()));
    }

    @PutMapping("/unfreeze/{id}")
    @ApiOperation(value = "解冻全返卷商品")
    public ResultMessage<Boolean> unfreeze(@PathVariable String id,@RequestBody ReturnActivityGoods returnActivityGoods) {
        return ResultUtil.data(returnActivityGoodsService.unfreeze(id,returnActivityGoods.getRemark()));
    }

    @ApiOperation(value = "根据店铺获取店铺全返商品")
    @GetMapping("/getListByStore")
    public ResultMessage<Object> getListByStore () {
        return ResultUtil.data(returnActivityGoodsService.getListByStore(Objects.requireNonNull(UserContext.getCurrentUser()).getExtendId()));
    }


}
